/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
package com.eelpo.cmmp.core.wicket.panel.grid.column;

import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.PropertyPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortStateLocator;
import org.apache.wicket.markup.html.basic.Label;

/**
 * <pre>
 * 属性列
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public class PropertyColumn<T> extends PropertyPopulator<T> implements IColumnHeader<T> {

	protected final String header;
	protected final String sort;
	protected final String property;
	protected final boolean isAllowSort;
	protected final ColumnLocation location;
	protected static final long serialVersionUID = -3873064282482683133L;

	public boolean isAllowSort() {
		return isAllowSort;
	}

	public String getProperty() {
		return property;
	}

	public String getSort() {
		return sort;
	}

	public String getHeader() {
		return header;
	}

	public ColumnLocation getLocation() {
		return location;
	}

	public PropertyColumn(String header, String property, boolean isAllowSort, ColumnLocation location) {
		super(property);
		this.location = location;
		this.header = header;
		this.property = property;
		this.isAllowSort = isAllowSort;
		this.sort = property;
	}

	public PropertyColumn(String header, String property, String sort, boolean isAllowSort, ColumnLocation location) {
		super(property);
		this.location = location;
		this.header = header;
		this.property = property;
		this.isAllowSort = isAllowSort;
		this.sort = sort;
	}

	public PropertyColumn(String header, String property, ColumnLocation location) {
		this(header, property, false, location);
	}

	@Override
	public Component newHeader(MarkupContainer parent, String id) {
		return new Label(id, getHeader());
	}

	@Override
	public Component newSortHeader(MarkupContainer parent, String id, ISortStateLocator dataProvider) {
		return new OrderPanel(id, getSort(), getHeader(), dataProvider);
	}
}